package com.stageadminserver.adminserver.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.stageadminserver.adminserver.service.DemandsService;
import com.stagecommon.common.pojo.Demands;
import com.stagecommon.common.pojo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 需求控制
 * @author: yxl
 * @since: 2021-11-30
 **/
@Slf4j
@RestController
@RequestMapping("/demands")
public class DemandsController {

    @Autowired
    private DemandsService demandsService;

    /**
     * 获取所有需求
     * @return
     */
    @PostMapping("/selectAllDemands")
    public RespBean selectAllDemands(){
        return RespBean.operationSuccess("查询成功",200,demandsService.listDemands());
    }
    
    /**
     * 根据id获取需求信息
     * @param demands
     * @return
     */
    @PostMapping("/selectDemandById")
    public RespBean selectDemandById(@RequestBody Demands demands){
        return demandsService.selectDemandDetailById(demands.getDemandId());
    }
    
    /**
     * 分页获取需求
     * @param currentPage
     * @param size
     * @param demands
     * @return
     */
    @PostMapping("/searchDemandsPage")
    public RespBean<IPage> searchDemandsPage(@RequestParam(defaultValue = "1") Integer currentPage,
                                         @RequestParam(defaultValue = "10") Integer size,
                                         @RequestBody Demands demands){
        return demandsService.searchDemandsPage(currentPage,size,demands);
    }

    /**
     * 根据id修改需求信息
     * @param demands
     * @return
     */
    @PostMapping("/changeDemandById")
    public RespBean<Integer> changeDemandById(@RequestBody Demands demands){
        return demandsService.updateDemandById(demands);
    }

    /**
     * 根据id删除需求
     * @param demands
     * @return
     */
    @PostMapping("/deleteDemandById")
    public RespBean<Integer> deleteDemandById(@RequestBody Demands demands){
        return demandsService.deleteDemandById(demands);
    }

}
